from random import randint
from time import sleep
from selenium.webdriver.support.select import Select
from selenium import webdriver

# driver = webdriver.Firefox();


driver = webdriver.Chrome();
driver.get('http://localhost/jxc/index.asp')

a = driver.find_elements_by_tag_name('input');
a[0].send_keys('admin');
a[1].send_keys('admin');
a[2].click();

driver.switch_to.frame('left');
sleep(1);
driver.find_element_by_css_selector('.menuall > tbody:nth-child(1) > tr:nth-child(13) > td:nth-child(1) > img:nth-child(1)').click();
sleep(1);
driver.find_element_by_css_selector('#g_6 > table > tbody > tr:nth-child(7) > td > table > tbody > tr > td:nth-child(2)').click();
sleep(1);
driver.switch_to.default_content();
driver.switch_to.frame('right');
driver.find_element_by_name('chkall').click();
sleep(1);
driver.find_elements_by_class_name('button')[1].click();
sleep(1);
driver.switch_to.alert.accept();
driver.find_elements_by_class_name('button')[0].click();
sleep(1);
driver.find_element_by_name('danwei').send_keys('T');
driver.find_element_by_name('submit').click();
sleep(1);
driver.switch_to.alert.accept();
sleep(1);
driver.switch_to.default_content();
driver.switch_to.frame('left');
driver.find_element_by_css_selector('#g_6 > table > tbody > tr:nth-child(5) > td > table > tbody > tr > td:nth-child(2)').click()
driver.switch_to.default_content();
driver.switch_to.frame('right');
sleep(1)
driver.find_elements_by_class_name('button')[0].click();
sleep(1);
driver.find_element_by_name('bigclass').send_keys('大象1');
driver.find_element_by_name('submit').click();
sleep(1);
driver.switch_to.alert.accept();
sleep(1);
driver.switch_to.default_content();
driver.switch_to.frame('left');
driver.find_element_by_css_selector('#g_6 > table > tbody > tr:nth-child(6) > td > table > tbody > tr > td:nth-child(2)').click();
sleep(1);
driver.switch_to.default_content();
driver.switch_to.frame('right');
sleep(1);
driver.find_elements_by_class_name('button')[0].click();
sleep(1);
se = Select(driver.find_element_by_name('bigclass'))
se.select_by_index(randint(0, len(se.options) - 1));
sleep(1);
driver.find_element_by_name('smallclass').send_keys('太空人');
driver.find_element_by_name('submit').click();
driver.switch_to.alert.accept();
sleep(1);
driver.switch_to.default_content();
driver.switch_to.frame('topFrame');
driver.find_element_by_link_text('安全退出').click();
sleep(1);
driver.switch_to.alert.accept();


sleep(2)
driver.quit()